|
A property, in some object-oriented programming languages, is a special sort of class member, intermediate between a field (or data member) and a method. Properties are read and written like fields, but property reads and writes are (usually) translated to get and set method calls. The field-like syntax is said to be easier to read and write than lots of method calls, yet the interposition of method calls allows for data validation, active updating (as of GUI visuals), or read-only 'fields'. That is, properties are intermediate between member code (methods) and member data (instance variables) of the class, and properties provide a higher level of encapsulation than public fields. == Support in languages == Programming languages that support properties include ActionScript 3, C#, D, Delphi/Free Pascal, F#, JavaScript, Objective-C 2.0, Python, Scala, Swift, Lua, and Visual Basic. Some object-oriented languages, such as Java, don't support properties, and require the programmer to define a pair of ''accessor'' and ''mutator'' methods instead. Oberon-2 provides an alternative mechanism using object variable visibility flags. Other languages designed for the Java Virtual Machine, such as Groovy, do natively support properties. While C++ doesn't have first class properties, they can be emulated due to operator overloading. Also note that some C++ compilers support first class properties (the Microsoft C++ compiler as an example). In most languages, properties are implemented as a pair of accessor/mutator methods, but accessed using the same syntax as for public fields. Omitting a method from the pair yields a ''read-only'' or an uncommon ''write-only'' property. In some languages with no built-in support for properties, a similar construct can be implemented as a single method that either returns or changes the underlying data, depending on the context of its invocation. Such techniques are used e.g. in Perl. Some languages (Ruby, Smalltalk) achieve property-like syntax using normal methods, sometimes with a limited amount of syntactic sugar. 抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Property (programming)」の詳細全文を読む スポンサード リンク
|